@extends('home.layouts')
@section('content')
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
        <div class="am-modal-dialog">
            <div class="am-modal-hd"><span id="commentTitle">发表评论</span>
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <input type="hidden" name="cid" value="">
                <div class="am-form-group">
                    <textarea class="commentTextarea" rows="5" id="doc-ta-1" style="border: beige;width: 100%"></textarea>
                </div>
                <a class="am-btn am-btn-xs am-btn-danger" style="float: left;margin-left: 15%;" data-am-modal-close>取消</a>
                <button class="am-btn am-btn-xs am-btn-primary" style="float: right;margin-right: 15%;" onclick="comment({{$c1['cid']}})">提交</button>
            </div>
        </div>
    </div>
    <div class="pet_article_dowload pet_dowload_more_top_off">
        <div class="pet_article_dowload_title">
            <div data-tab-panel-0 class="am-tab-panel am-active">
                <div class="pet_comment_list_block">
                    <div class="pet_comment_list_block_l"><img src="{{$c1['avatar']}}-40X40" alt=""></div>
                    <div class="pet_comment_list_block_r">
                        <div class="pet_comment_list_block_r_info">{{$c1['username']}}</div>
                        <div class="pet_comment_list_block_r_text"><a style="color: black" href="{{url('commentdetail/'.$c1['id'])}}">{{$c1['comment']}}</a></div>
                        <div class="pet_comment_list_block_r_bottom">
                            <div class="pet_comment_list_bottom_info_l">{{date('Y-m-d H:i:s',$c1['created_at'])}}</div>
                            <br>
                            <div class="pet_comment_list_bottom_info_r">
                                <span onclick="star({{$c1['id']}},4)">
                                    <i id="hand_{{$c1['id']}}"
                                       @if(in_array($c1['id'],$starCommentIds))
                                       style="color:red;"
                                       @endif
                                       class="iconfont">&#xe631;</i>
                                    @foreach($avatars as $avatar)
                                    <div class="pet_comment_list_block_l" style="width: 24px;height: 24px"><img src="{{$avatar['avatar']}}-40X40" alt=""></div>
                                    @endforeach
                                    <span id="likkkkk_{{$c1['id']}}">{{$c1['like']}}</span>人点赞
                                </span>
                                <span onclick="replyComment({{$c1['id']}})"
                                      data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 330, height: 245}"> 回复({{$c1['replycount']}})</span></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="pet_article_dowload_content pet_dowload_more_top_bg">
            <div class="pet_article_dowload_triangle pet_dowload_more_top_san"></div>

            @foreach($comments as $c1)
            <div data-tab-panel-0 class="am-tab-panel">
                <div class="pet_comment_list_block">
                    <div class="pet_comment_list_block_l"><img src="{{$c1['avatar']}}-40X40" alt=""></div>
                    <div class="pet_comment_list_block_r">
                        <div class="pet_comment_list_block_r_info">{{$c1['username']}}</div>
                        <div class="pet_comment_list_block_r_text"><a style="color: black" href="{{url('commentdetail/'.$c1['id'])}}">{{$c1['comment']}}</a></div>
                        <div class="pet_comment_list_block_r_bottom">
                            <div class="pet_comment_list_bottom_info_l">{{date('Y-m-d H:i:s',$c1['created_at'])}}</div>
                            <div class="pet_comment_list_bottom_info_r">
                            <span onclick="star({{$c1['id']}},4)"><i
                                        @if(in_array($c1['id'],$starCommentIds))
                                        style="color:red;"
                                        @endif
                                        id="hand_{{$c1['id']}}" class="iconfont">&#xe631;</i><span id="likkkkk_{{$c1['id']}}">{{$c1['like']}}</span>
                            </span>
                            <span onclick="replyComment({{$c1['id']}})"
                                  data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 330, height: 245}"> 回复({{$c1['replycount']}})
                            </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @endforeach
        </div>
    </div>
    <div class="am-tabs-bd pet_pl_list">
        </div>
    @endsection

@section('javascript')
    <script>
        function star(id,type){
            $.post('{{url('star')}}',{'_token':'{{csrf_token()}}','id':id,'type':type},function(res){
                if(res.msg){
                    $("#hand_"+id).css('color','red');
                    $("#likkkkk_"+id).text('').text($("#likkkkk_"+id).text()+1);
                }
                layer.msg(res.msg);
            })
        }
        function comment(id){
            var comments=$(".commentTextarea").val();
            if($("input[name='cid']").val()==''){
                var postData={'_token':'{{csrf_token()}}','comment':comments,'cid':id};
            }else{
                var reply=$("input[name='cid']").val();
                var postData={'_token':'{{csrf_token()}}','comment':comments,'cid':id,'reply':reply};
            }
            $.post('{{url('insertcomment')}}',postData, function (res) {
                if(res.status){
                    $("#doc-modal-1").modal('close');
                    layer.msg(res.msg);
                    location.reload();
                }else{
                    layer.msg(res.msg);
                }
            })
        }

        function replyComment(cid){
            $("#commentTitle").text('回复评论');
            $("input[name='cid']").val(cid);
        }
    </script>
    @endsection